package libs;


/**
 *              This class represents a student.
 * @author      Jan Papousek
 * @version     2009-03-02
 */
public class Student {

    /**
     *          Student's name.
     */
    private String name;

    /**
     *          Student's id.
     */
    private int id;


    /**
     * @param   name    Student's name.
     * @param   id      Student's id.
     * @throws  NullPointerException if the name is null.
     * @throws  IllegalArgumentException if the id is <= 0.
     */
    public Student (String name, int id) {
        if (name == null) {
            throw new NullPointerException("Parameter 'name' is null.");
        }
        if (id < 0) {
            throw new IllegalArgumentException("ID is <= 0");
        }
        this.name = name;
        this.id = id;
    }

    /**
     *          It returns student's id.
     * 
     * @return  Student's id.
     */
    public int getId () {
        return id;
    }

    /**
     *          It returns student's name.
     * 
     * @return  Student's name.
     */
    public String getName () {
        return name;
    }

    /**
     *          Two students are the same if they have the same id.
     */
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Student)) {
            return false;
        }
        Student stud = (Student)o;
        return (stud.getId() == this.getId());
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + this.id;
        return hash;
    }

}
